# 封装是指将数据和操作数据的方法绑定在一起，以保护数据不被外部直接访问。可以通过将属性设置为私有（使用双下划线 __ 前缀）来实现
class BackAccount:
    def __init__(self, username, balance):
        self.username = username
        self.__balance = balance

    # 存钱
    def cunqian(self, amount):
        self.__balance += amount
    # 取钱
    def quqian(self, amount):
        if amount > self.__balance:
            print('取款金额大于余额，取款失败！')
        else:
            self.__balance -= amount

    # 查看当前余额
    def get_balance(self):
        return self.__balance

def main():
    account = BackAccount('张三', 1000)
    account.cunqian(500)
    print('当前最新余额为：', account.get_balance())
    account.quqian(300)
    print('当前最新余额为：', account.get_balance())
    # print(account._BackAccount__balance)

if __name__ == '__main__':
    main()